package org.tis.tools.abf.module.ac.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.abf.module.ac.controller.request.AcOperatorMenuRequest;
import org.tis.tools.abf.module.ac.entity.AcOperatorMenu;
import org.tis.tools.abf.module.ac.service.IAcOperatorMenuService;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.model.log.enums.OperateType;
import org.tis.tools.starter.operatelog.annotation.OperateLog;

import javax.validation.constraints.NotBlank;

/**
 * 操作员重组菜单
 * acOperatorMenu的Controller类
 * 
 * @author Auto Generate Tools
 * @date 2018/04/23
 */
@RestController
@Validated
@RequestMapping("/acOperatorMenu")
@Slf4j
public class AcOperatorMenuController extends BaseController<AcOperatorMenu>  {

    @Autowired
    private IAcOperatorMenuService acOperatorMenuService;


    @ApiOperation(value = "新增父操作员重组菜单",notes = "传入AcOperatorMenuRequest类作为参数")
    @OperateLog(type = OperateType.ADD,desc = "新增父操作员重组菜单")
    @PostMapping("/addRoot")
    public ResultVO addRoot(@RequestBody @Validated @ApiParam(value = "AcOperatorMenuRequest",name = "传入的AcOperatorMenuRequest类",required = true) AcOperatorMenuRequest acOperatorMenuRequest) {
        acOperatorMenuService.addRoot(acOperatorMenuRequest);
        return ResultVO.success("新增成功！");
    }


    @ApiOperation(value = "新增子操作员重组菜单",notes = "传入AcOperatorMenuRequest类作为参数")
    @OperateLog(type = OperateType.ADD,desc = "新增子操作员重组菜单")
    @PostMapping("/addChild")
    public ResultVO addChild(@RequestBody @Validated @ApiParam(value = "AcOperatorMenuRequest",name = "传入的AcOperatorMenuRequest类",required = true) AcOperatorMenuRequest acOperatorMenuRequest) {
        acOperatorMenuService.addChild(acOperatorMenuRequest);
        return ResultVO.success("新增成功！");
    }


    @ApiOperation(value = "修改操作员重组菜单",notes = "传入AcOperatorMenuRequest类作为参数")
    @OperateLog(type = OperateType.UPDATE,desc = "修改操作员重组菜单")
    @PutMapping
    public ResultVO update(@RequestBody @Validated @ApiParam(value = "AcOperatorMenuRequest",name = "传入的AcOperatorMenuRequest类",required = true) AcOperatorMenuRequest acOperatorMenuRequest) {
        AcOperatorMenu acOperatorMenu = acOperatorMenuService.selectById(acOperatorMenuRequest.getGuid());
        if (acOperatorMenu == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        acOperatorMenu = acOperatorMenuService.change(acOperatorMenuRequest);
        return ResultVO.success("修改成功！",acOperatorMenu);
    }

    @ApiOperation(value = "删除操作员重组菜单",notes = "传入操作员重组菜单的GUID作为参数")
    @OperateLog(type = OperateType.DELETE,desc = "删除操作员重组菜单")
    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "操作员重组菜单的GUID",required = true) String id) {
        AcOperatorMenu acOperatorMenu = acOperatorMenuService.selectById(id);
        if (acOperatorMenu == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        acOperatorMenuService.deleteAllOperatorMenu(id);
        return ResultVO.success("删除成功");
    }

    @ApiOperation(value = "根据GUID查询操作员重组菜单",notes = "传入操作员重组菜单的GUID作为参数")
    @GetMapping("/{id}")
    public ResultVO detail(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "操作员重组菜单的GUID",required = true) String id) {
        AcOperatorMenu acOperatorMenu = acOperatorMenuService.selectById(id);
        if (acOperatorMenu == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功", acOperatorMenuService.getDetail(id));
    }

    @ApiOperation(value = "分页查询操作员重组菜单",notes = "传入分页信息作为参数")
    @PostMapping("/list")
    public ResultVO list(@RequestBody @Validated @ApiParam(value = "page",name = "分页信息",required = true) SmartPage<AcOperatorMenu> page) {
        return  ResultVO.success("查询成功", acOperatorMenuService.getPage(page.getPageObj(), page.getConditionWrapper()));
    }

    @ApiOperation(value = "根据操作员GUID查询操作员重组菜单",notes = "传入分页信息和操作员GUID作为参数")
    @PostMapping("/queryByOperatorId/{id}")
    public ResultVO queryByOperatorId(@RequestBody @Validated @ApiParam(value = "page",name = "分页信息",required = true) SmartPage<AcOperatorMenu> page,@PathVariable @NotBlank(message = "操作员GUID不能为空") @ApiParam(value = "id",name = "操作员GUID",required = true) String id) {
        return  ResultVO.success("查询成功", acOperatorMenuService.queryByOperatorId(page.getPageObj(), page.getConditionWrapper(), id));
    }
}

